home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 12 - 1996 / 12.10 Oct 96 / AdownsJavaObjects / DecafObject.java < prev    next >
Encoding:
Text File  |  1996-09-11  |  3.7 KB  |  183 lines  |  [TEXT/R*ch]

  1. /*
  2.  
  3. Listing 3: DecafObject .java
  4.  
  5. DecafObject.java
  6. Define and create a new instance of our generic object.
  7.  
  8. */
  9.  
  10. // Import the generic Java classes.
  11. import java.applet.*;
  12. import java.awt.*;
  13. import java.io.*;
  14. import java.lang.*;
  15.  
  16. //    Our class definition.
  17. public    class DecafObject extends Canvas
  18. {
  19.     Color                    theBackgroundColor = Color.white;
  20.     Color                    theTextColor = Color.white;
  21.     Color                    menuColor[] = {     Color.black, Color.green,
  22.                                                             Color.pink, Color.blue,
  23.                                                             Color.lightGray, Color.red,
  24.                                                             Color.cyan, Color.magenta,
  25.                                                             Color.white, Color.darkGray,
  26.                                                             Color.orange, Color.yellow,
  27.                                                             Color.gray };
  28.     DecafObject        theNextDecafObject;
  29.     DecafObject        thePreviousDecafObject;
  30.     Rectangle            boundsRect = new Rectangle();
  31.     String                theText = new String();
  32.     boolean                isSelected = false, insideGrow = false;
  33.     static    int        panelDefaultX = 10, panelDefaultY = 10;
  34.      static    int        panelDefaultWidth = 40;
  35.     static    int        panelDefaultHeight = 20;
  36.     static    int        buttonDefaultX = 10, buttonDefaultY = 10;    static    int        buttonDefaultWidth = 40;
  37.     static    int        buttonDefaultHeight = 20;
  38.     static    int        textAreaDefaultX = 10;
  39.     static    int        textAreaDefaultY = 10;
  40.     static    int        textAreaDefaultWidth = 40;
  41.     static    int        textAreaDefaultHeight = 20;
  42.     int                        theID = 0;
  43.  
  44.     //    theObjectType: 0 = Panel, 1 = Button, 2 = Text Area
  45.     int                        theObjectType = 0;
  46.  
  47.     //    theTextAlignment: 0 = Left, 1 = Center, 2 = Right
  48.     int                        theTextAlignment = 0;
  49.  
  50.  
  51.     public    DecafObject()
  52.     {
  53.     }
  54.  
  55.     public    void    DoSetupCanvasComponent()
  56.     {
  57.         if ( theObjectType == 0 )
  58.             boundsRect.reshape( panelDefaultX, panelDefaultY,
  59.                     panelDefaultWidth, panelDefaultHeight );
  60.         else if ( theObjectType == 1 )
  61.             boundsRect.reshape( buttonDefaultX, buttonDefaultY,
  62.                     buttonDefaultWidth, buttonDefaultHeight );
  63.     }
  64.  
  65.     public    void    DoSetID( int newID )
  66.     {
  67.         this.theID = newID;
  68.     }
  69.  
  70.     public    int        DoGetID()
  71.     {
  72.         return( this.theID );
  73.     }
  74.  
  75.     public    void    DoSetBounds( Rectangle newBounds )
  76.     {
  77.         this.boundsRect = newBounds;
  78.     }
  79.  
  80.     public    Rectangle    DoGetBounds()
  81.     {
  82.         return( this.boundsRect );
  83.     }
  84.  
  85.     public    void    DoSetInsideGrow( boolean theSetting )
  86.     {
  87.         this.insideGrow = theSetting;
  88.     }
  89.  
  90.     public    boolean    DoGetInsideGrow()
  91.     {
  92.         return( this.insideGrow );
  93.     }
  94.  
  95.     public    void    DoSetSelected( boolean theSetting )
  96.     {
  97.         this.isSelected = theSetting;
  98.     }
  99.  
  100.     public    boolean    DoGetSelected()
  101.     {
  102.         return( this.isSelected );
  103.     }
  104.  
  105.     public    void    DoSetText( String theString )
  106.     {
  107.         theText = theString;
  108.     }
  109.  
  110.     public    String    DoGetText()
  111.     {
  112.         return( this.theText );
  113.     }
  114.  
  115.     public    void    DoSetObjectType( int objType )
  116.     {
  117.         theObjectType = objType;
  118.     }
  119.  
  120.     public    int        DoGetObjectType()
  121.     {
  122.         return( this.theObjectType );
  123.     }
  124.  
  125.     public    void    DoSetTextAlignment( int textAlign )
  126.     {
  127.         theTextAlignment = textAlign;
  128.     }
  129.  
  130.     public    void    doSetBackColor( int theColor )
  131.     {
  132.         theBackgroundColor = menuColor[ theColor ];
  133.     }
  134.  
  135.     public    Color    doGetBackColor()
  136.     {
  137.         return( this.theBackgroundColor );
  138.     }
  139.  
  140.     public    void    doSetTextColor( int theColor )
  141.     {
  142.         theTextColor = menuColor[ theColor ];
  143.     }
  144.  
  145.     public    Color    doGetTextColor()
  146.     {
  147.         return( this.theTextColor );
  148.     }
  149.  
  150.     public    void    doSetNextDecafObject( DecafObject theDecafObject )
  151.     {
  152.         theNextDecafObject = theDecafObject;
  153.     }
  154.  
  155.     public    void    doSetPreviousDecafObject( DecafObject 
  156.             theDecafObject )
  157.     {
  158.         thePreviousDecafObject = theDecafObject;
  159.     }
  160.  
  161.     public    DecafObject    doGetNextDecafObject()
  162.     {
  163.         return    theNextDecafObject;
  164.     }
  165.  
  166.     public    DecafObject    doGetPreviousDecafObject()
  167.     {
  168.         return    thePreviousDecafObject;
  169.     }
  170.  
  171.     public void    DoDeleteDecafObject()
  172.     {
  173.         if ( theNextDecafObject != null )
  174.             theNextDecafObject.doSetPreviousDecafObject(
  175.                     thePreviousDecafObject );
  176.  
  177.         if ( thePreviousDecafObject != null )
  178.             thePreviousDecafObject.doSetNextDecafObject(
  179.                     theNextDecafObject );
  180.     }
  181.  
  182.